#include<bits/stdc++.h>
using namespace std;
int usfcmr[1000005];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a;
    cin>>a;
    for(int nn=1;nn<=a;nn++)
    {
        double d[100005];
        double a[100005];
        double v[100005];
        int p[100005];
        int n,m,l;
        double vc;
        cin>>n>>m>>l>>vc;
        int pd=0,pdd=0,pddd=0;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]!=0)pd=1;
            if(a[i]>=0)pdd=1;
            if(a[i]<=0)pddd=1;
        }
        for(int i=1;i<=m;i++)
        {
            cin>>p[i];
        }
        int jsq=0;
        if(pd==0)
        {
            for(int i=1;i<=n;i++)
            {
                if(v[i]>vc)jsq++;
            }
            cout<<jsq<<" "<<m-1<<"\n";
            return 0;
        }
        jsq=0;
        if(pddd==0)
        {
            for(int i=1;i<=n;i++)
            {
                if(v[i]>=vc)jsq++;
                else
                {
                    double tm=(vc-v[i])*1.0000000000000/a[i];
                    double xx=v[i]*tm*1.000000000000+0.5000000000000*a[i]*tm*tm;
                    if(d[i]+xx<=l)jsq++;
                }
            }
            if(m==1)m=2;
            cout<<jsq<<" "<<m-1<<"\n";
        }
        else cout<<"3 3"<<"\n";
    }
    return 0;
}
